class BaseController {
  constructor(service) {
    console.log("进入弗雷的构造方法:", service);
    this.service = service;
  }
  async saveOrUpdate(ctx, next) {
    const obj = ctx.request.body;
    const result = await this.service.saveOrUpdate(obj);
    //4.查看存储的结果,告知前端创建成功
    ctx.body = {
      code: 200,
      data: result,
      msg: "维护成功",
    };
  }
  async getById(ctx, next) {
    console.log("进入子类的getList方法", this, ctx);
    //1.获取用户的ID
    const { id } = ctx.params;
    //2.根据用户的ID查询用户的头像信息
    const result = await this.service.getById(id);
    ctx.body = {
      data: result,
      msg: "查询成功",
      code: 200,
    };
  }
  async getList(ctx, next) {
    const { pageSize, pageNum, queryCondition } = ctx.request.body;
    const result = await this.service.getList(
      pageNum,
      pageSize,
      queryCondition
    );
    //4.查看存储的结果,告知前端创建成功
    ctx.body = {
      code: 200,
      data: result,
      msg: "查询成功",
    };
  }
  async deleteById(ctx, next) {
    console.log(" ctx.params", ctx);

    //1.获取用户的ID
    const { id } = ctx.params;
    //2.根据用户的ID查询用户的头像信息
    const result = await this.service.deleteById(id);
    ctx.body = {
      data: result,
      msg: "查询成功",
      code: 200,
    };
  }
}

module.exports = BaseController;
